package com.situ.storehouse.controller;


import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



import com.situ.storehouse.entity.Wares;
import com.situ.storehouse.service.WaresService;
import com.situ.storehouse.service.WaresServiceImpl;
import com.situ.storehouse.util.BaseController;
import com.situ.storehouse.vo.LayuiTableVO;

//商品管理控制类
@WebServlet("/warescontroller")
public class WaresController extends BaseController {
	private static final long serialVersionUID = 1L;
	WaresService service=new WaresServiceImpl();
	//打开商品管理界面
	public void page(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
		req.getRequestDispatcher("/WEB-INF/wares.jsp").forward(req, resp);
	}
	//往表格中放数据
		public LayuiTableVO list(Integer page,Integer limit,String keyword){
			List<Wares> list=service.select(page,limit,keyword);
			LayuiTableVO vo=new LayuiTableVO();
			vo.setCode(0);
			vo.setData(list);
			vo.setCount(service.count(keyword));
			return vo;
		}
		
		//删除数据
		public void delete(Integer id) {
			service.delete(id);
		}
		
		//查询某个商品信息
		public Wares select(Integer id){
			return service.select(id);
			}

		//增加+修改员工信息
		@SuppressWarnings("unlikely-arg-type")
		public void save(Wares wares) {
			if(wares.getId()==null || wares.getId().equals("")) {
				service.add(wares);
			}else {
				wares.setId(wares.getId());
				service.update(wares);
			}
		}



}
